from sqlalchemy import create_engine
from sqlalchemy import Column, String, Integer
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import declarative_base
from urllib.parse import quote_plus

# 链接是需要指定要用到的MySQL数据库
username = "root"
password = "Tcdn@2007."
encoded_password = quote_plus(password)
host = "172.16.100.10"
port = "3306"
database_name = "flask_1"

engine = create_engine(f'mysql+pymysql://{username}:{encoded_password}@{host}:{port}/{database_name}?charset=utf8')
# engine = create_engine('mysql+pymysql://root:Tcdn@2007.@172.16.100.10:3306/flask_1?charset=utf8')
Base = declarative_base()  # 生成SQLORM基类


class User(Base):
    # 对应MySQL中数据表的名字
    __tablename__ = 'user'

    # 创建字段
    id = Column(Integer, primary_key=True)
    user_id = Column(String(50), nullable=False)
    user_name = Column(String(50), nullable=False)
    head_img = Column(String(200))
    short_description = Column(String(300))
